import React, {Component} from 'react';
import {Redirect} from "react-router-dom";
import {connect} from 'react-redux';

export default function (CurrentComponent) {
    @connect(
        state => ({isLogin:state.userInfo.isLogin}),
    )
    class TargetComponent extends Component{
        render() {
            const {...params} = this.props
            const {pathname} = this.props.history.location
            if(pathname !== '/login' && !this.props.isLogin) {
                return <Redirect to='/login'></Redirect>
            }
            if(pathname === '/login' && this.props.isLogin) return <Redirect to='/'></Redirect>
            return <CurrentComponent {...params} />
        }
    }
    return TargetComponent
}